package backend;

import java.sql.ResultSet;
import java.sql.Statement;

public class Bag
{
	
	private int id;
	private long licensePlate;
	private String originatingAirport;
	private int routeId;
	private RouteLeg[] bagRoute;
	
	public Bag(int theId, long theLicense, String origAirport, int theRouteId, RouteLeg[] theRoute)
	{
		id = theId;
		licensePlate = theLicense;
		originatingAirport = origAirport;
		routeId = theRouteId;
		bagRoute = theRoute;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getOriginatingAirport() {
		return originatingAirport;
	}
	
	public long getLicensePlate() {
		return licensePlate;
	}
	
	public int getRouteId() {
		return routeId;
	}
	
	public void setRouteId(int id) {
		routeId = id;
	}
	
	public RouteLeg[] getBagRoute() {
		return bagRoute;
	}
	
	public void setBagRoute(Warehouse wh, RouteLeg[] legs) {
		
		bagRoute = legs;
		for (int i=0; i<legs.length; i++)
		{
			if (legs[i].getId() == -1)
				wh.insertRouteLeg(legs[i]);
		}
		
		int rId = wh.findRouteByLegs(legs);
		// Was there a matching route?
		
		if (rId != -1)
		{
			routeId = rId;
		}
		// Was there no matching route?
		else
		{
			// Insert a new route and add the route bridges
			routeId = wh.insertRoute(legs.length);
			wh.updateRoute(routeId, legs);
		}
		
		wh.updateBagRoute(id, routeId);
	}

	public void setOriginatingAirport(String air) {
		originatingAirport = air;
	}
	
}
